var util = require('../../utils/util.js')
var app = getApp();
let stickyAPIData = require("../../components/componentsAPI.js").sticky
Page({
  data: {
    TabCur: 0,
    items: ['按时间倒序', '分值从大到小'],
    stickyAPIData,
    scrollTop: 0
  },

  onReady() {
    let list1 = []
    for (let i = 0; i < 15; i++) {
      list1.push("列表  " + i)
    }
    this.setData({
      list1
    })

    let $sticky = this.selectAllComponents(".sticky")
    $sticky.forEach((el) => {
      el._init()
    })

  },
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },

  onShow: function () {
    // 加载动画
    //this.loadModal();
  },
  
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },

  loadModal() {
    this.setData({
      loadModal: true
    })
    setTimeout(() => {
      this.setData({
        loadModal: false
      })
    }, 2000)
  },

  skipPage: function (e) {
    var url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    })
  }, 

  onLoad: function () {

    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },

  DateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    //模拟加载
    setTimeout(function () {
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1500);
  }
  
})
